// pages/my/my.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
		uid: "",
		array: ["中国", "美国", "巴西", "日本"],
		index: 0,
		arrayname:null,
		shielding: "false",
		items: [
			{value: '0', name: '记忆模式', checked: 'true'},
      {value: '1', name: '随机模式'},
		],
		current: 0,
		onlinkinp:null,
		ontitle:null,
		listid:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		var that = this;
		 // 调用函数时，传入new Date()参数，返回值是日期和时间
		 var time = util.formatTime(new Date());
		 // 再通过setData更改Page()里面的data，动态更新页面的数据
		 this.setData({
			 time: time,
			 listid:options.listid
		 });
		console.log(time)
		that.getlist()
	},
//列表
getlist(e){
	let that = this; 
	var prolist = wx.getStorageSync('prolist')
	wx.request({
		url: 'https://wxtp.hephp.cn/Api/Group/get', //仅为示例，并非真实的接口地址
		data: {
			uid:prolist.data.uid,
		},
		header: {
			'content-type': 'application/json' // 默认值
		},
		success (res) {
			let prolist = res.data.data;
		//	console.log(prolist)
			let array =  []
			prolist.forEach((item, index) => {
				array[index] = item.group
			})
			that.setData({
				array:array,
				arrayname:array[0]
			})
		}
	})
},


	// navigateBack(e){
	// 	wx.switchTab({
	// 		url: '/pages/link/link',
	// 	})
	// },
	onordinary(e){
		
		wx.navigateTo({
			url: '/pages/putong/putong',
		})
	},
	onrandom(e){
		let that = this
		let id = that.data.listid
		wx.navigateTo({
			url: '/pages/rand/rand',
		})
	},
	// 输入链接
	onlinkurl(e){
		console.log(e);
	},
	onlinkinp(e){
		let that = this
		that.setData({
			onlinkinp:e.detail.value
		})
		console.log(e.detail.value);
	},
	// 链接标题
	ontitle(e){
		console.log(e.detail.value);
		let that = this
		that.setData({
			ontitle:e.detail.value
		})

	},
	// 选择分组
	bindPickerChange(e){
		console.log('picker发送选择改变，携带值为', e.detail.value)
		let that = this
		let array = that.data.array
		let  index = e.detail.value
		console.log(index)
		this.setData({
			index: index,
			arrayname:array[index]
		})
	},
	// switch打开关闭
	switch1Change(e) {
		let that = this;
		console.log("switch1 发生 change 事件，携带值为", e.detail.value)
		let shielding = e.detail.value
		that.setData({
			shielding:shielding
		})
		console.log(shielding);
	},
	//创建普通链接
	onadd(e){
		let that = this;
		let id = that.data.listid
		let uid =  wx.getStorageSync('prolist').data.uid
		let arrayname =that.data.arrayname
		let shielding = that.data.shielding
		let ontitle = that.data.ontitle
		let onlinkinp = that.data.onlinkinp
    wx.request({
      url: 'https://wxtp.hephp.cn/Api/Url/edit', //仅为示例，并非真实的接口地址
      data: {
				id:id,
        uid:uid,
				group:arrayname,
				title:ontitle,
				category:1,
				url:onlinkinp
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        let code = res.data.code;
				if(code==200){
					wx.switchTab({
						url: '../link/link',
					})
				}
      }
    })
		//console.log("022222")
	},


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },


})